<layout name="page" />
<block name="content">
	{:widget('page_header/search',array('name'=>'共享客户','search'=>'S'))}
	<div class="operate-panel">
		<a class="btn btn-return" onclick="go_return_url();">返回</a>
		<div class="split"></div>
		<a id="btn_save" class="btn">保存</a>
	</div>
	<!-- 列表显示区域  -->
	<div class="sub-frame">
		<form id="form_data" name="form_data" method="post">
			<div class="sub-sidebar big">
				<table class="table table-bordered">
					<thead>
						<tr>
							<th class="text-center checkbox col-3">
							<input type="checkbox" class="toggle-select-all" data="contact_id[]"/>
							</th>
							<th>姓名</th>
							<th>公司</th>
							<th>部门</th>
							<th>职位</th>
							<th>业务员</th>
							<th>产品</th>
						</tr>
					</thead>
					<tbody class="tbody">
						<volist name="contact_list" id="vo">
							<tr id="{$vo.id}">
								<td class="text-center col-3 checkbox">
								<input type="checkbox" name="contact_id[]" value="{$vo.id}" />
								</td>
								<td> {$vo.name} </td>
								<td> {$vo.compnay_name} </td>
								<td> {$vo.dept} </td>
								<td> {$vo.position} </td>
								<td> {$vo.salesman_name} </td>
								<td> {$vo.product} </td>
							</tr>
						</foreach>
					</tbody>
				</table>
			</div>
			<div class="sub-content small">
				<table class="table table-bordered">
					<thead>
						<tr>
							<th>&nbsp;</th>
							<th> 姓名 </th>
							<th> 部门 </th>
							<th> 职位 </th>
						</tr>
					</thead>
					<tbody>
						<volist name="user_list" id="data">
							<tr id="{$data.id}">
								<td class="col-3 checkbox text-center">
								<input type="checkbox" id="user_{$data.id}" name="user_id[]" value="{$data.id}" />
								</td>
								<td>{$data.name}</td>
								<td>{$data.dept_name}</td>
								<td>{$data.position_name}</td>
							</tr>
						</foreach>
					</tbody>
				</table>
			</div>
		</form>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global', 'suggest'], function() {
			var $ = layui.jquery;

			$(".sub-sidebar tbody tr").click(function() {
				$(".sub-sidebar  tr").attr("class", "");
				$(this).attr("class", "active");
				send_ajax("{:url('get_share_list')}", "id=" + $(this).attr("id"), function(data) {
					show_data(data);
				});
			});

			function show_data(result) {
				$("input[name='user_id[]']").each(function() {
					$(this).prop('checked', false);
				});
				for (var s in result.data) {					
					$("#user_" + result.data[s]).prop('checked', true);
				}
			};
			
			$("#btn_save").click(function() {
				var vars = $("#form_data").serialize();
				send_ajax("{:url('share_save')}", vars, function(ret) {
					if (ret.status) {
						layer.msg(ret.info);
						location.reload(true);
					} else {
						layer.msg(ret.info);
					}
				});
			});
		});
	</script>
</block>